package com.gopay.common.hessian;

import org.apache.commons.lang3.StringUtils;

/**
 * hessian接收端，接收随机数
 * 
 * @ReceiveHessianKey.java
 * @author yaobo
 * @2013-7-27 上午11:05:44 www.gopay.com.cn Inc.All rights reserved.
 */
public class ReceiveHessianKey {
    public static final ThreadLocal<String> keyLocal = new ThreadLocal<String>();

    private ReceiveHessianKey() {
    }

    /**
     * 用于初始化数据，一般情况下不要使用，切忌
     * 
     * @param value
     * @return
     */
    public static String getInstance(String value) {
        String key = keyLocal.get();
        if (StringUtils.isBlank(key)) {
            key = value;
            keyLocal.set(value);
        }

        return key;
    }

    /**
     * 获取接收到的随机数
     * 
     * @return
     */
    public static String getInstance() {
        return getInstance("");
    }

    public static void main(String[] args) {
        String key = ReceiveHessianKey.getInstance("ca59913e-44da-4bb3-9aba-c6459f7803aa");
        System.out.println(key);

        key = ReceiveHessianKey.getInstance();
        System.out.println(key);
    }
}
